// pages/message/index.js
const app = getApp()
var id = 1;
var page = 1;
var pagesize = 12;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    messageList: '',
    selected: true,
    selected1: false
  },
  selected: function(e) {
    id = e.currentTarget.id;
    page = 1;
    this.setData({
      selected1: false,
      selected: true,
    })
    this.getMessageList()
  },
  selected1: function(e) {
    id = e.currentTarget.id
    page = 1;
    this.setData({
      selected: false,
      selected1: true,
    })
    this.getMessageList()
  },
  //获取留言列表
  getMessageList: function() {
    console.log('椰树', page)
    var that = this;
    var data = [];
    data['type'] = id;
    data['page'] = page;
    data['pagesize'] = pagesize;
    var url = 'We_Community/getMessageAllList';
    var calkdata = app.netWorkRequest(that, data, url, 'messageList')
  },
  goMessageCode: function(e) {
    console.log('传递信息', e.currentTarget)
    var id = e.currentTarget.id;
    var nids = e.currentTarget.dataset.nids;
    var sta = e.currentTarget.dataset.sta;
    wx.navigateTo({
      url: '../messageCode/index?id=' + id + '&nids=' + nids + '&sta=' + sta,
    })
  },
  //加载更多留言列表
  getMessageListLoadMore: function() {
    console.log('椰树', page)
    // 页数+1
    page = page + 1;
    console.log('椰树', page)
    var that = this;
    var data = [];
    data['type'] = id;
    data['page'] = page;
    data['pagesize'] = pagesize;
    var url = 'We_Community/getMessageAllList';
    var f_data = that.data.messageList;
    var calkdata = app.netWorkRequestLoadMore(that, data, url, 'messageList', f_data);
  },
  goVisitorInfo: function(e) {
    console.log('传递信息', e.currentTarget.id)
    var id = e.currentTarget.id;
    wx.navigateTo({
      url: '../visitorInfo/index?id=' + id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    id = 1;
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    page = 1;
    this.getMessageList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.onShow();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    // 显示加载图标
    wx.showLoading({
      title: '玩命加载中',
    })
    this.getMessageListLoadMore();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})